const dotenv = require("dotenv")
const { resolve } = require("path")

;(() => {
  try {
    const RUNTIME = process.env.NODE_ENV
    let envFile = RUNTIME ? "./.env.dev" : RUNTIME ? "./.env.prod" : ""
    if (!envFile) throw new Error("can not get the environment")

    envFile = resolve(__dirname, envFile)
    dotenv.config({ path: envFile })
  } catch (err) {
    console.error(err)
    process.exit(1)
  }
})()
